const { Post } = require("../database/sequlize");

// 获取所有文章
exports.getAllPosts = async () => {
  return await Post.findAll();
};

// 获取单个文章
exports.getPostById = async (id) => {
  return await Post.findByPk(id);
};

// 新建文章
exports.createPost = async (newPostData) => {
  return Post.create(newPostData);
};

// 更新文章内容
exports.updatePost = async (id, updatedPostData) => {
  await Post.update(updatedPostData, {
    where: { id },
  });
  return await Post.findByPk(id);
};

// 删除文章
exports.deletePost = async (id) => {
  return await Post.destroy({
    where: { id },
  });
};
